'use strict';

goog.provide('Blockly.Arduino.storer');
goog.require('Blockly.Arduino');

//写入EEPROM
Blockly.Arduino.forBlock['xnr_EEPROM_write_put'] = function() {
    var value_NAME = Blockly.Arduino.valueToCode(this, 'NAME', Blockly.Arduino.ORDER_ATOMIC);
    var checkbox_NAME = this.getFieldValue('NAME') == 'TRUE';
    var dropdown_read_get = this.getFieldValue('read_get');
    var value_DATA = Blockly.Arduino.valueToCode(this, 'DATA', Blockly.Arduino.ORDER_ATOMIC);
    Blockly.Arduino.definitions_['include_' + '.EEPROM_Initf'] = '#include <EEPROM.h>';
    var code = 'EEPROM.' + dropdown_read_get + '(' + value_NAME + ', ' + value_DATA + ');\n';
    return code;
};

Blockly.Arduino.forBlock['xnr_EEPROM_get'] = function() {
    var value_NAME = Blockly.Arduino.valueToCode(this, 'NAME', Blockly.Arduino.ORDER_ATOMIC);
    var checkbox_NAME1 = this.getFieldValue('NAME1') == 'TRUE';
    var value_DATA = Blockly.Arduino.valueToCode(this, 'DATA', Blockly.Arduino.ORDER_ATOMIC);
    Blockly.Arduino.definitions_['include_' + '.EEPROM_Initf'] = '#include <EEPROM.h>';
    var code = 'EEPROM.get(' + value_NAME + ', ' + value_DATA + ');\n';
    return code;
};

Blockly.Arduino.forBlock['xnr_EEPROM_read_get'] = function() {
    var value_NAME = Blockly.Arduino.valueToCode(this, 'NAME', Blockly.Arduino.ORDER_ATOMIC);
    var code = 'EEPROM.read(' + value_NAME + ')';
    return [code, Blockly.Arduino.ORDER_ATOMIC];
};

Blockly.Arduino.forBlock['xnr_EEPROM_begin'] = function() {
    var text_size = this.getFieldValue('size');
    Blockly.Arduino.definitions_['include_' + '.EEPROM_Initf'] = '#include <EEPROM.h>';
    var code = 'EEPROM.begin(' + text_size + ');\n';
    return code;
};

Blockly.Arduino.forBlock['xnr_EEPROM_commit'] = function() {
    var code = 'EEPROM.commit()';
    return [code, Blockly.Arduino.ORDER_ATOMIC];
};

Blockly.Arduino.forBlock['xnr_EEPROM_end'] = function() {
    var code = 'EEPROM.end();\n';
    return code;
};

Blockly.Arduino.forBlock['xnr_EEPROM_lianjie'] = function() {
    var value_NAME = Blockly.Arduino.valueToCode(this, 'NAME', Blockly.Arduino.ORDER_ATOMIC);
    var code = value_NAME + ';\n';
    return code;
};

